<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('机器人信息列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>机器人名称：</label>
                            <input type="text" name="robotName"/>
                        </li>
                        <li>
                            <label>机器人图标路径：</label>
                            <input type="text" name="robotIcon"/>
                        </li>
                        <li>
                            <label>机器人电量，范围0 - 100：</label>
                            <input type="text" name="robotBattery"/>
                        </li>
                        <li>
                            <label>删除者：</label>
                            <input type="text" name="deleteBy"/>
                        </li>
                        <li>
                            <label>删除时间：</label>
                            <input type="text" class="time-input" placeholder="请选择删除时间" name="deleteTime"/>
                        </li>
                        <li>
                            <label>删除标志：</label>
                            <input type="text" name="deleteFlag"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="robot:info:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="robot:info:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="robot:info:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="robot:info:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('robot:info:edit')}]];
    var removeFlag = [[${@permission.hasPermi('robot:info:remove')}]];
    var datasRobotType = [[${@dict.getType('sys_robot_type')}]];
    var datasRobotStatus = [[${@dict.getType('sys_robot_status')}]];
    var prefix = ctx + "robot/info";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "机器人信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'robotId',
                    title: '机器人ID',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'robotName', align: 'center',
                    title: '机器人名称'
                },
                {
                    field: 'robotType', align: 'center',
                    title: '机器人类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datasRobotType, value);
                    }
                },
                {
                    field: 'robotStatus', align: 'center',
                    title: '机器人状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datasRobotStatus, value);
                    }
                },
                {
                    field: 'robotIcon',
                    title: '机器人图标',
                    formatter: function (value, row, index) {
                        // 如果有图标路径则显示图片，否则显示默认文本
                        return value ? '<img src="' + value + '" style="width: 50px; height: 50px; object-fit: contain;" />' : '无图标';
                    }
                },
                {
                    field: 'robotBattery',
                    title: '机器人电量',
                    formatter: function (value, row, index) {
                        // 将电量值转换为数字，默认为0
                        const batteryLevel = Number(value) || 0;
                        let iconClass = 'fa-battery-empty';

                        // 根据电量水平设置不同图标
                        if (batteryLevel >= 75) {
                            iconClass = 'fa-battery-full';
                        } else if (batteryLevel >= 50) {
                            iconClass = 'fa-battery-three-quarters';
                        } else if (batteryLevel >= 25) {
                            iconClass = 'fa-battery-half';
                        } else if (batteryLevel > 0) {
                            iconClass = 'fa-battery-quarter';
                        }

                        // 返回带图标和百分比的HTML
                        return `<i class="fa ${iconClass}" aria-hidden="true"></i> ${batteryLevel}%`;
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.robotId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.robotId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>